package Mr_11_20;

import java.util.Scanner;

public class roman {
    public static void main(String[] args) {
        String userInput;
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入：");
        while (true) {
            userInput = sc.next();
            boolean flag = checkStr(userInput);
            if (flag) {
                break;
            } else {
                System.out.println("当前字符串不符合规范，请重新输入：");
            }
        }
        String romannumber = "";
        for (int i = 0; i < userInput.length(); i++) {
            char cr = userInput.charAt(i);
            int index = cr - 48;   //ASCLL码表
            romannumber += changeToRoman(index);
        }
        System.out.println(romannumber);
    }

    public static String changeToRoman(int index) {
        String[] romanArr = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
        return romanArr[index];
    }

    public static boolean checkStr(String str) {
        //检测长度
        if (str.length() > 9) {
            return false;
        }
        //检测数字
        for (int i = 0; i < str.length(); i++) {
            char cr = str.charAt(i);
            if (cr > '9' || cr < '0') {
                return false;
            }
        }
        return true;
    }
}
